﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using PSE.Tools.SchemaComparer.Library;

namespace PSE.Tools.SchemaComparer.WindowsApp
{
    [Serializable]
    public class Configurations
    {
        private string _configPath;

        public string ConfigPath
        {
            get
            {
                return _configPath;
            }
        }

        public Configurations()
        {
            _configPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\configuration.xml";
        }


        public string ComparerToolPath
        {
            get;
            set;
        }

        public string ComparerToolAbsolutePath
        {
            get
            {
                if (this.ComparerToolPath.StartsWith(@".\"))
                    return System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + this.ComparerToolPath.Replace(@".\", @"\");
                else
                    return this.ComparerToolPath;

            }
        }

        public void Save()
        {
            XmlSerializer ser = new XmlSerializer(typeof(Configurations));
            ser.SerializeToFile(_configPath, this);
        }

        public void Load()
        {
            if (!File.Exists(_configPath))
            {
                this.ComparerToolPath = string.Empty;
                return;
            }

            XmlSerializer ser = new XmlSerializer(typeof(Configurations));
            Configurations c = ser.DeserializeFromFile<Configurations>(_configPath);

            this.ComparerToolPath = c.ComparerToolPath;
        }
    }
}
